#include <iostream>
#include <cstring>

int const maxn = 1007;
long long const mo = 1000000007;
long long f[maxn][maxn];
int a[maxn];
int b[maxn];
int n, m;

void init()
{
	memset(f, 0, sizeof(f));
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	while (std::cin >> n >> m) {
		init();
		for (int i = 1; i <= n; i++) std::cin >> a[i];
		for (int i = 1; i <= m; i++) std::cin >> b[i];

		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++) {
				if (a[i] == b[j]) {
					f[i][j] = (f[i - 1][j - 1] * 2 + 1) % mo;
					f[i][j] += f[i][j - 1] + f[i - 1][j] - 2 * f[i - 1][j - 1];
					f[i][j] %= mo;
				} else {
					f[i][j] = f[i][j - 1] + f[i - 1][j] - f[i - 1][j - 1];
					f[i][j] %= mo;
				}
			}

		/*
		std::cout << "\n";
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				std::cout << f[i][j] << " ";
			}
			std::cout << "\n";
		}
		*/
		std::cout << (f[n][m] + mo) % mo << "\n";
	}
}

